package com.dycx.payment.service.impl;


import com.dycx.common.RestResponse;
import com.dycx.common.enums.SourceEnum;
import com.dycx.payment.dto.PaymentOrderDTO;
import com.dycx.payment.enums.PayTypeEnum;
import com.dycx.payment.service.AppPayService;
import com.dycx.payment.service.JsapiPayService;
import com.dycx.payment.service.PayService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 支付实现类
 *
 * @author wuzongbin
 * @since 2024-01-16 09:57:09
 */

@Service
@AllArgsConstructor
@Slf4j
public class PayImpl implements PayService {
    private JsapiPayService jsapiPayService;
    private AppPayService appPayService;

    /**
     * 支付实现方法
     *
     * @param dto
     * @return
     */
    @Override
    public RestResponse<?> pay(PaymentOrderDTO dto) {
        //微信支付
        if (PayTypeEnum.WEIXIN.getCode().equals(dto.getPayType())) {
            if (SourceEnum.ANDROID_APP.getCode().equals(dto.getSource()) || SourceEnum.IOS_APP.getCode().equals(dto.getSource())) {
                return RestResponse.success(appPayService.appPay(dto));
            } else if (SourceEnum.WX_MP.getCode().equals(dto.getSource()) || SourceEnum.WX_MINI_APP.getCode().equals(dto.getSource())) {
                return RestResponse.success(jsapiPayService.jsapiPay(dto));
            }
        }

        return RestResponse.fail("支付参数不正确");
    }

}

